<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>键盘按键</title>
</head>

<body>
  <input type="text" id="inp">
  <script>
    var inp = document.getElementById('inp')
    // console.log(inp);
    inp.onkeydown = function () {
      if (event.keyCode == 13) {
        console.log("确认")
        console.log(this.value)
      }
      // console.log(event.keyCode)
    }
  </script>
</body>

</html>